import React from 'react';
import { observer, inject, action } from 'mobx-react';
import { History } from 'react-router'

@inject('store')
@observer
class Home extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
    };
  }

  componentWillMount() {
    const { history, store } = this.props;
    //console.log('History', history);
    //console.log(window.location);
    let code = this.getQueryString('code');
    //console.log('code', code);
    if(code && code.length > 0) {
      store.setLogin(code);
      setTimeout(() => {
        history.push('/palace');
      }, 0)
    } else {
      window.location="https://oauth.taobao.com/authorize?response_type=code&client_id=24543960&redirect_uri=https://sxhd.ews.m.jaeapp.com/manage/gugong/";
    }
  }

  getQueryString(name) {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    console.log('window.location', window.location);
    var r = window.location.search.substr(1).match(reg);
    if(r!=null) return  unescape(r[2]);
    return null;
  }


  render() {
    return (
      <div></div>
    );
  }
}


export default Home;
